﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Skewworks.Win.Motif.Glide
{
    public partial class GlideWindow : UserControl, IEmbeddedControl
    {

        private bool _sizeV, _sizeH;
        private Point _sizeRef;
        private ISettings _settings;

        public GlideWindow()
        {
            _settings = new GlideWindowSettings(this);
            InitializeComponent();
        }

        public ISettings Settings
        {
            get { return _settings; }
        }

        private void GlideWindow_Load(object sender, EventArgs e)
        {
            this.Width = 320;
            this.Height = 240;
            this.BackColor = Color.White;
        }

        private void GlideWindow_MouseMove(object sender, MouseEventArgs e)
        {
            if (_sizeH || _sizeV)
            {
                if (_sizeH)
                    this.Width += e.X - _sizeRef.X;
                if (_sizeV)
                    this.Height += e.Y - _sizeRef.Y;
            }
            else
            {
                if (e.X >= this.Width - 8)
                {
                    if (e.Y >= this.Height - 8)
                        this.Cursor = Cursors.SizeNWSE;
                    else
                        this.Cursor = Cursors.SizeWE;
                }
                else if (e.Y >= this.Height - 8)
                    this.Cursor = Cursors.SizeNS;
                else
                    this.Cursor = Cursors.Default;
            }
            _sizeRef = new Point(e.X, e.Y);
        }

        private void GlideWindow_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.X >= this.Width - 8)
            {
                if (e.Y >= this.Height - 8)
                {
                    _sizeH = true;
                    _sizeV = true;
                }
                else
                    _sizeH = true;
            }
            else if (e.Y >= this.Height - 8)
                _sizeV = true;
        }

        private void GlideWindow_MouseUp(object sender, MouseEventArgs e)
        {
            _sizeH = false;
            _sizeV = false;
        }

    }
}
